<?php
//include_once $_SERVER['DOCUMENT_ROOT'].'/phorm/core/Object.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/phorm/database/core/IDatabaseColumn.php';

class DatabaseColumn implements IDatabaseColumn
{
	public    $defaultValue;
	public    $length;
	public    $column;
	public    $field_type;
	public    $html_field;
	public    $unique  = false;
	public    $isDirty = false;

	protected $model;
	protected $data;
	
	public function getModel()
	{
		return $this->model;
	}
	
	public function __toString()
	{
		return "[phorm ".get_class($this)."]";
	}
	
	public function __get($property)
	{
		if ($property == 'value' && isset($this->data['value']))
			//return $this->data['value'];
			return $this->data['value'];
	}
	
	public function __set($property, $value)
	{
		if (!$this->data)
			$this->data = array('value'=>'');
			//$this->data = new Object();
		
		switch ($property)
		{
			case 'value':
				
				if($value != $this->data['value'])
					$this->data['value'] = $value;
				//$this->data['value'] = $value;
				break;
			
			case 'userDefinedValue':
				$this->handleUserDefinedValue($value);
				if($value != $this->data['value'])
				{
					$this->data['value']  = $value;
					$this->isDirty        = true;
					$this->model->isDirty = true;
				}
				//$this->data['value'] = $value;
				break;
		}
		
	}
	
	public function __destruct()
	{
		unset($this->model);
		$this->model = null;
	}
	
	public function handleUserDefinedValue(&$value){ }
	
	/*public function toHTML()
	{ 
		$value = @$this->value;
		$html  = "<tr class=\"phorm-toHTML-row\">\n\t";
		$html .= "<td class=\"phorm-toHTML-label\" align=\"right\" valign=\"top\">".$this->column.": </td>\n\t";
		
		if ($this->field_type == 'text')
			$html .= "<td class=\"phorm-toHTML-input\"><textarea rows=\"20\" cols=\"50\" name=\"{$this->column}\">{$value}</textarea></td>\n";
		else
			$html .= "<td class=\"phorm-toHTML-input\"><input name=\"{$this->column}\" type=\"text\" value=\"{$value}\"></td>\n";
		
		$html  .= "<tr>\n";
		
		return $html;
	}*/
	
}
?>
